/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * RandomHandWindow.java
 *
 * Created on 27/11/2011, 00:10:13
 */
package fallen.deck.front_end;

import fallen.deck.Drecker;
import fallen.deck.entity.Card;
import fallen.deck.entity.Deck;
import fallen.deck.front_end.customCardPanel.iCard;
import javax.swing.ImageIcon;

/**
 *
 * @author Carlos S. Moreno <CarlosS.Moreno@gmail.com>
 */
public class RandomHandWindow extends javax.swing.JDialog {

    private Deck deck;
    private iCard card1, card2, card3, card4, card5;
    private int cardSize;

    /** Creates new form RandomHandWindow */
    public RandomHandWindow(Deck deck) {
        this.setIconImage(new ImageIcon(getClass().getResource("/icons/16/eye.png")).getImage());
        initComponents();
        this.deck = deck;
        cardSize = 311;
        Deck auxDeck = deck.clone();
        card1 = new iCard(cardSize, (Card) auxDeck.getCards().remove((int) (Math.random() * (auxDeck.getCards().size()-1))));
        card2 = new iCard(cardSize, (Card) auxDeck.getCards().remove((int) (Math.random() * (auxDeck.getCards().size()-1))));
        card3 = new iCard(cardSize, (Card) auxDeck.getCards().remove((int) (Math.random() * (auxDeck.getCards().size()-1))));
        card4 = new iCard(cardSize, (Card) auxDeck.getCards().remove((int) (Math.random() * (auxDeck.getCards().size()-1))));
        card5 = new iCard(cardSize, (Card) auxDeck.getCards().remove((int) (Math.random() * (auxDeck.getCards().size()-1))));
        pnlCards.add(card1);
        pnlCards.add(card2);
        pnlCards.add(card3);
        pnlCards.add(card4);
        pnlCards.add(card5);
    }

    public void sort() {
        int fCard = (int) (Math.random() * deck.getCards().size());
        Drecker.inform("Random: " + fCard);
        Deck auxDeck = deck.clone();
        card1.setCard((Card) auxDeck.getCards().remove(fCard));
        card2.setCard((Card) auxDeck.getCards().remove((int) (Math.random() * (auxDeck.getCards().size()-1))));
        card3.setCard((Card) auxDeck.getCards().remove((int) (Math.random() * (auxDeck.getCards().size()-1))));
        card4.setCard((Card) auxDeck.getCards().remove((int) (Math.random() * (auxDeck.getCards().size()-1))));
        card5.setCard((Card) auxDeck.getCards().remove((int) (Math.random() * (auxDeck.getCards().size()-1))));
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        toolBar = new javax.swing.JToolBar();
        btnSort = new javax.swing.JButton();
        pnlCards = new javax.swing.JPanel();

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
        setTitle("Mano Inicial Simulada");
        setModal(true);
        setResizable(false);

        toolBar.setFloatable(false);
        toolBar.setOrientation(javax.swing.SwingConstants.VERTICAL);
        toolBar.setRollover(true);

        btnSort.setIcon(new javax.swing.ImageIcon(getClass().getResource("/icons/16/sort.png"))); // NOI18N
        btnSort.setText("Mezclar");
        btnSort.setFocusable(false);
        btnSort.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        btnSort.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        btnSort.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnSortActionPerformed(evt);
            }
        });
        toolBar.add(btnSort);

        pnlCards.setLayout(new java.awt.GridLayout(1, 0));

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addComponent(pnlCards, javax.swing.GroupLayout.DEFAULT_SIZE, 1083, Short.MAX_VALUE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(toolBar, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(toolBar, javax.swing.GroupLayout.DEFAULT_SIZE, 306, Short.MAX_VALUE)
            .addComponent(pnlCards, javax.swing.GroupLayout.DEFAULT_SIZE, 306, Short.MAX_VALUE)
        );

        java.awt.Dimension screenSize = java.awt.Toolkit.getDefaultToolkit().getScreenSize();
        setBounds((screenSize.width-1158)/2, (screenSize.height-334)/2, 1158, 334);
    }// </editor-fold>//GEN-END:initComponents

private void btnSortActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnSortActionPerformed
    sort();
}//GEN-LAST:event_btnSortActionPerformed
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton btnSort;
    private javax.swing.JPanel pnlCards;
    private javax.swing.JToolBar toolBar;
    // End of variables declaration//GEN-END:variables
}
